﻿Imports CupsApp.Data
Imports CupsApp.Service
Partial Public Class background
    Inherits System.Web.UI.Page
    Public _data As New InterviewData
    Public _service As New CupsDomainService

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lvlMsg.Text = ""
        If Not IsPostBack Then
            If IsNothing(Request.QueryString("clientID")) Then
                CType(Master.FindControl("lnkNewClient"), LinkButton).Enabled = False
                CType(Master.FindControl("lnkNewClient"), LinkButton).Text = "> New Client/Family <"
            Else
                Client_ID.Value = Request.QueryString("clientID")
                _data = _service.GetBackgroundInterview(Client_ID.Value)
                wwDataBinder1.DataBind()
            End If
        End If
    End Sub

#Region "Click Events"

    Protected Sub lnkPersonal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkPersonal.Click
        Response.Redirect(String.Format("personal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHealthLegal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHealthLegal.Click
        Response.Redirect(String.Format("health_legal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHousing_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHousing.Click
        Response.Redirect(String.Format("housing.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkFollowUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkFollowUp.Click
        Response.Redirect(String.Format("follow_up.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkStatus_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkStatus.Click
        Response.Redirect(String.Format("status.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkExit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkExit.Click
        Response.Redirect(String.Format("exit.aspx?clientID={0}", Client_ID.Value))
    End Sub

#End Region

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click

        If VerifyCheckBoxes Then
            wwDataBinder1.Unbind()
            _service.UpdateBackgroundInterview(Client_ID.Value, _data)
            lvlMsg.ForeColor = Drawing.Color.Green
            lvlMsg.Text = "* Background information was saved successfully!"
            'In the case of an insert, get the clientID
        Else
            lvlMsg.ForeColor = Drawing.Color.Red
            lvlMsg.Text = "* If you have checked yes, you are also required to select the month duration!"
        End If
        

    End Sub

    Public Function VerifyCheckBoxes() As Boolean

        Dim AllowSave As Boolean = False

        If chkRecently1.Checked Then
            If chkCorrection1.Checked Or chkCorrection2.Checked Or chkCorrection3.Checked Or chkCorrection4.Checked Or chkCorrection5.Checked Then : AllowSave = True
            Else : Return False
            End If
        End If

        If chkIsReleasedFromHealthFacility1.Checked Then
            If chkHealthReleaseTime1.Checked Or chkHealthReleaseTime2.Checked Or chkHealthReleaseTime3.Checked Or chkHealthReleaseTime4.Checked Or chkHealthReleaseTime5.Checked Then : AllowSave = True
            Else : Return False
            End If
        End If

        If chkIsReleaseFoster1.Checked Then
            If chkTimeFoster1.Checked Or chkTimeFoster2.Checked Or chkTimeFoster3.Checked Or chkTimeFoster4.Checked Or chkTimeFoster5.Checked Then : AllowSave = True
            Else : Return False
            End If
        End If

        If chkIsEvicted1.Checked Then
            If chkEvictedTime1.Checked Or chkEvictedTime2.Checked Or chkEvictedTime3.Checked Or chkEvictedTime4.Checked Or chkEvictedTime5.Checked Then : AllowSave = True
            Else : Return False
            End If
        End If

        If chkIsEmployed1.Checked Then
            If chkEmployedTime1.Checked Or chkEmployedTime2.Checked Or chkEmployedTime3.Checked Or chkEmployedTime4.Checked Or chkEmployedTime5.Checked Then : AllowSave = True
            Else : Return False
            End If
        End If

        Return AllowSave

    End Function
End Class